/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const morgan = require("morgan");
const { join } = require("path");

require("dotenv").config();

const port = 3000;

// 实例化一个express
const app = express();

// morgan
app.use(morgan("combined"));

// static
app.use(
  "/static",
  express.static(join(__dirname, "helpers"), { index: false })
);

// json
app.use(bodyParser.json());

// query string
app.use(
  bodyParser.urlencoded({
    extended: false,
  })
);

// CORS
app.use(cors({ maxAge: 24 * 60 * 60 }));

// 路由
app.use("/mail", require("./routes/mail"));
app.use("/upload", require("./routes/upload"));

// server
app.listen(port, () => {
  console.log(`Listening on port ${port} ...`);
});
